<template>
  <div>
    <el-card class="box-card" style="margin-top: 0;">
      <div slot="header" class="clearfix">
        <span>筛选查询</span>
      </div>
      <div class="text item">
        <el-form
          :model="queryParams"
          ref="queryForm"
          :inline="true"
        >
          <el-form-item label="" prop="provinceName">
            <el-select
              v-model="queryParams.provinceName"
              placeholder="所在省份"
              clearable
              size="small"
              @change="changeProvince"
            >
              <el-option
                v-for="(item, index) in provinceList"
                :key="index"
                :label="item.provinceName"
                :value="item.provinceId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="cityName">
            <el-select
              v-model="queryParams.cityName"
              placeholder="所在城市"
              clearable
              size="small"
            >
              <el-option
                v-for="(item, index) in cityList"
                :key="index"
                :label="item.name"
                :value="item.cityId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="campsiteName">
            <el-input
              v-model="queryParams.campsiteName"
              placeholder="请输入营地名称"
              clearable
              size="small"
            />
          </el-form-item>
          <el-form-item label="" prop="phone">
            <el-input
              v-model="queryParams.phone"
              placeholder="请输入手机号码"
              clearable
              size="small"
            />
          </el-form-item>
          <el-form-item label="" prop="idCard">
            <el-input
              v-model="queryParams.idCard"
              placeholder="请输入身份证号"
              clearable
              size="small"
            />
          </el-form-item>

          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
            >搜索
            </el-button
            >
            <el-button
              type="primary"
              icon="el-icon-refresh"
              size="mini"
              @click="resetQuery"
            >重置
            </el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </el-card>

    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>数据列表</span>

        <el-button
          type="primary"
          size="mini"
          style="float: right; margin-left: 10px;"
          @click="handleExport"
        >导出全量表
        </el-button>
      </div>
      <div class="text item">
        <el-table v-loading="loading" :data="tableList">
          <el-table-column label="订单编号" align="center" prop="orderNo"/>
          <el-table-column label="所在省份" align="center" prop="provinceName"/>
          <el-table-column label="所在城市" align="center" prop="cityName"/>
          <el-table-column label="所在中学" align="center" prop="school"/>
          <el-table-column label="营地名称" align="center" prop="campsiteName" min-width="150"/>
          <el-table-column label="姓名" align="center" prop="studentName"/>
          <el-table-column label="手机号" align="center" prop="phone"/>
          <el-table-column label="身份证号" align="center" prop="idCard" min-width="150"/>
          <el-table-column label="实付金额" align="center" prop="payAmount"/>
          <el-table-column label="支付时间" align="center" prop="payTime"/>
          <el-table-column label="支付状态" align="center" prop="status"/>
          <el-table-column label="支付方式" align="center" prop="payWay">
            <template slot-scope="scope">
              <span v-if="scope.row.payWay==1">银联支付</span>
              <span v-if="scope.row.payWay==2">支付宝支付</span>
              <span v-if="scope.row.payWay==3">微信支付</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.qisi"
        :limit.sync="queryParams.offset"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script>
  import {GetProvinceList, GetCityList} from "@/api/campSystem/campOper";
  import {GetYTFOrderList} from "@/api/campSystem/financial";
  export default {
    name: "RefundOrder",
    data() {
      return {
        loading: false,// 表格加载loading
        queryParams: {
          qisi: 1,
          offset: 10,
          provinceName: null,
          cityName: null,
          campsiteName: null,
          phone: null,
          idCard: null,
        },
        total: 0,// 数据总条数
        tableList: [], // 表格数据列表
        provinceList: [],// 省份列表
        cityList: [],// 城市列表
      };
    },
    created() {
      this.getProvince();
      this.getList();
    },
    methods: {
      // 重置按钮
      resetQuery() {
        this.cityList = [];
        this.$refs['queryForm'].resetFields();
        this.handleQuery();
      },
      // 搜索按钮
      handleQuery() {
        this.queryParams.qisi = 1;
        this.queryParams.offset = 10;
        this.getList();
      },
      // 获取列表
      getList() {
        this.loading = true;
        GetYTFOrderList(this.queryParams)
          .then(response => {
            console.log(response);
            if (response.code != 200) {
              this.loading = false;
              return this.msgError(response.msg);
            }
            this.tableList = response.data;
            this.total = response.total;
            this.loading = false;
          })
          .catch(error => {
            console.log(error);
            this.loading = false;
          });
      },
      // 改变省份，获取城市列表
      changeProvince(value) {
        GetCityList(value+'').then((res) => {
          if(res.code != 200){
            return this.$message.error(res.msg);
          }
          this.cityList = res.data;
          this.queryParams.cityName = null;
          console.log(res)
        }).catch(err=>{
          console.log(err);
        });
      },
      // 获取省份列表
      getProvince() {
        GetProvinceList()
          .then(response => {
            this.provinceList = response;
          })
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download(
          "modules-campsite/finance/ExportYTK",
          {},
          `已退费订单全量表.xlsx`
        );
      },
    },
  }
</script>

<style lang="scss">
  @import "@/assets/styles/card.scss";
</style>

